<script src="{{ getAssets }}js/amazeui.datatables.min.js?v={{ assets_version }}"></script>
<script>
    var curing;
    var tables = $('#dataTables').DataTable({
        "sAjaxSource": location.href
        , "bLengthChange": false
        , "fnServerData": function (sSource, aoData, fnCallback) {
            var queryParams = checkQueryTableData(aoData);
            $.post(sSource, JSON.stringify(queryParams), function (resp) {
                if (resp.aaData.curing) {
                    curing = resp.aaData.curing;
                    $('#curing_name').html(curing.Name);
                    $('#curing_type').html(curing.CuringType == 1 ? '重点养护' : '临时养护');
                    $('#time_limit').html(curing.TimeLimit + '天');
                    $('#product_typeid').html(curing.ProductTypeid == 20 ? '隐形眼镜' : '护理产品');
                    $('#brand_name').html(curing.BrandName);
                    $('#need_check_number').html(curing.NeedCheckNumber);
                }
                var pageData = {
                    'aaData': resp.aaData.curing_data,
                    'iTotalDisplayRecords': resp.iTotalDisplayRecords,
                    'iTotalRecords': resp.iTotalRecords
                };
                fnCallback(pageData);
            }, 'json')
        }
        , order: []
        , columns: [
            {
                "bSortable": false, render: function (data, type, full, meta) {
                    return '<input type="checkbox" class="selectOne" value="' + full.Id + '">';
                }
            }
            , {
                "bSortable": false, render: function (data, type, full, meta) {
                    return productTypeidName(full.Products.TypeId);
                }
            }
            , {
                "bSortable": false, render: function (data, type, full, meta) {
                    return full.Products.BrandName;
                }
            }
            , {
                "bSortable": false, render: function (data, type, full, meta) {
                    return full.Products.Name;
                }
            }
            , {
                "bSortable": false, render: function (data, type, full, meta) {
                    return full.Products.ColourNumber;
                }
            }
            , {
                "bSortable": false, render: function (data, type, full, meta) {
                    return full.Products.Spec;
                }
            }
            , {
                "bSortable": false, render: function (data, type, full, meta) {
                    return full.Products.CastAway;
                }
            }
            , {
                "bSortable": false, render: function (data, type, full, meta) {
                    return full.Products.ShelfLife;
                }
            }
            , {
                "bSortable": false, render: function (data, type, full, meta) {
                    return full.Products.Unit;
                }
            }
            , {
                "bSortable": false, render: function (data, type, full, meta) {
                    return full.Inventory.Snd.sph;
                }
            }
            , {
                "bSortable": false, render: function (data, type, full, meta) {
                    return full.Inventory.Snd.cyl;
                }
            }
            , {
                "bSortable": false, render: function (data, type, full, meta) {
                    return timetransDate(full.manufacture_date);
                }
            }
            , {
                "bSortable": false, render: function (data, type, full, meta) {
                    return timetransDate(full.expiry_date);
                }
            }
            , {
                "bSortable": false, render: function (data, type, full, meta) {
                    return full.lot_number;
                }
            }
        ]
        , "aLengthMenu": [100, 200, 300]
		,'bLengthChange': true
        , "serverSide": true
        , "bPaginate": true
        , "bFilter": false	//是否启动过滤、搜索功能
        , "bInfo": true //是否显示页脚信息，DataTables插件左下角显示记录数
        , "bProcessing": true //DataTables载入数据时，是否显示‘进度’提示
    });
    $('.selectAll').click(function () {
        if ($(this).prop('checked') != false) {
            $('.selectOne').prop('checked', true);
        } else {
            $('.selectOne').prop('checked', false);
        }
    });
    $('#select-product').click(function () {
        var sel = $('.selectOne:checked');
        if (sel.length <= 0) {
            layer.alert("请选择需要养护的商品");
            return false;
        }
        var _data = {curing_id: curing.Id, curing_data_id: []};
        $.each(sel, function (index, value) {
            _data.curing_data_id.push(Number($(this).val()));
        });
        _data.curing_data_id = JSON.stringify(_data.curing_data_id);
        $.post('{{ urlfor "CuringController.SetProductCuringDataStatus" }}', _data, function (res) {
            if (res.code == 1) {
                layer.alert(res.msg);
                return false;
            }
            location = '{{ urlfor "CuringController.CuringProductCheck" }}/' + res.data;
        }, 'json');

    });
</script>
